package nl.hu.verbrandendephoenix.view;

import java.util.ArrayList;

import nl.hu.verbrandendephoenix.shared.Auction;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.VerticalPanel;

public class TopAuctions {

	private Panel pnlTopAuctions;
	private Grid grdTopAuctions;
	public TopAuctions() {
		pnlTopAuctions = new VerticalPanel();
		pnlTopAuctions.addStyleName("post");
	}

	public Panel constructForm(Grid g) {
		pnlTopAuctions = new VerticalPanel();
		
		Label title = new Label("Top 5 veilingen:");
		title.addStyleName("h1");
		
		pnlTopAuctions.add(title);

		pnlTopAuctions.add(g);

		return pnlTopAuctions;
	}

	public Grid printResult(ArrayList<Auction> stats) {
		grdTopAuctions = new Grid(stats.size() + 1, 3);
		grdTopAuctions.setWidget(0, 0, new HTML("<b>Positie</b>"));
		grdTopAuctions.setWidget(0, 1, new HTML("<b>Veilingnaam</b>"));
		grdTopAuctions.setWidget(0, 2, new HTML("<b>Aantal biedingen</b>"));
		int rowCounter = 1;
		int positionCounter = 1;
		for(Auction a : stats) {
			grdTopAuctions.setWidget(rowCounter, 0, new Label(positionCounter + "."));
			grdTopAuctions.setWidget(rowCounter, 1, new Anchor(a.getAuctionName() + "", "#viewauction-" + a.getAuctionID()));
			if (a.getAuctionName().equals("") || a.getAuctionName() == null)
				grdTopAuctions.setWidget(rowCounter, 1, new Anchor(a.getAuctionID() + "", "#viewauction-" + a.getAuctionID()));
			grdTopAuctions.setWidget(rowCounter, 2, new Label(a.getUserID() + ""));
			rowCounter++;
			positionCounter++;
		}
		return grdTopAuctions;
	}
}